<template>
  <ul class="top-menu">
    <li @click="go()" :class="{'active':routeName == 'home'}"><span>驻村辅导</span></li>
    <li @click="goShare()" :class="{'active':routeName == 'redCloudHeadline'}"><span>互动分享</span></li>
    <li @click="goPolicyDocument()" :class="{'active':routeName == 'longVideo'}"><span>相关政策</span></li>
  </ul>
</template>

<script>
  export default {
    name: 'workVillageMenu',
    components: {
    },
    data () {
      return {
        routeName: 'home'
      }
    },
    created () {
      this.userInfo = this.$localStorage.get('userInfo')
    },
    methods: {
      go () {
        let flag = false
        if (this.userInfo.type === '6') {
          this.$router.push({name: 'tutoringVillage'})
          return
        } else if (this.userInfo.type === '7') {
          this.$router.push({name: 'tutoringVillageTeacher'})
          return
        } else if (this.userInfo.type === '8') {
          this.$router.push({name: 'tutoringVillageLeader'})
          this.$store.state.userGroup = {
            groupId: this.userInfo.mainGroupId,
            groupName: this.userInfo.mainGroupName
          }
          return
        }
        this.userInfo.canGroups.map((v) => {
          if (v.userType === '6') {
            flag = true
            this.$router.push({name: 'tutoringVillage'})
          } else if (v.userType === '7') {
            flag = true
            this.$router.push({name: 'tutoringVillageTeacher'})
          } else if (v.userType === '8') {
            flag = true
            this.$router.push({name: 'tutoringVillageLeader'})
            this.$store.state.userGroup = v
          }
        })
        if (!flag) {
          this.showNoRoleAlart()
        }
      },
      showNoRoleAlart () {
        this.tools.tip('你没有权限访问')
      },
      goShare (name) {
        if (this.getRole()) {
          this.$router.push({path: `/redfriendscircleShare/workVillage`})
        } else {
          this.showNoRoleAlart()
        }
      },
      goPolicyDocument () {
        let id = '1f2c47f8273a43efb0b9dfd2fe554808'
        this.$router.push({path: `/policyDocument/${id}`})
      },
      getRole () {
        let flag = false
        if (this.userInfo.type === '6') {
          flag = true
        } else if (this.userInfo.type === '7') {
          flag = true
        } else if (this.userInfo.type === '8') {
          flag = true
        }
        this.userInfo.canGroups.map((v) => {
          if (v.userType === '6') {
            flag = true
          } else if (v.userType === '7') {
            flag = true
          } else if (v.userType === '8') {
            flag = true
          }
        })
        return flag
      }
    }
  }
</script>

<style scoped lang="scss">
  @import "@/common/stylus/moon.scss";
  .top-menu {
    border-bottom:1px solid $border-color;
    li.active {
      span {
        font-weight:bolder;
      }
    }
  }
</style>
